const express=require('express')
const router= express.Router();
const db=require('../../utils/db')

module.exports = router

router.post('/getreport',function(req,res,next){
  let mysql=`SELECT * FROM(
    SELECT t3.*,t4.user_name FROM (
    SELECT * FROM 
    (
    SELECT * FROM order_information WHERE order_time BETWEEN '${req.body.date1}' AND '${req.body.date2}'
    )AS t1  
    JOIN  menu_file AS t2 ON t1.order_menu_id=t2.menu_id 
    )AS t3 JOIN USER AS t4 ON t3.order_user_id=t4.user_id
    )AS t5 JOIN pay_method AS t6 ON t5.order_pay_way=t6.pay_id ORDER BY order_time`
  db(mysql,function(err,data){
    console.log('err', err);
    if (err) {
        return res.json({
            code: 500,
            msg: '查询失败'
        })
    }
    res.json({
      code: 200,
      msg: '查询成功',
      data:data

  })
})
})

router.post('/getrepeat',function(req,res,next){
  let mysql=`SELECT * FROM(
    SELECT t3.*,t4.user_name FROM (
    
    (SELECT * FROM order_information  AS t1 JOIN  menu_file AS t2 ON t1.order_menu_id=t2.menu_id )
    
    )AS t3 JOIN USER AS t4 ON t3.order_user_id=t4.user_id
    )AS t5 JOIN pay_method AS t6 ON t5.order_pay_way=t6.pay_id ORDER BY order_time`;
     db(mysql,function(err,data){
       if (err) {
    return res.json({
        code: 500,
        msg: '查询失败'
        
        })
    }
       res.json({
          code: 200,
          msg: '查询成功',
          data:data
  })
})
})